<? include_once("../module/common_setting.php"); //引入通用的设置文件?>



<?
//TODO 在leyin网站faq板块引发错误。
//include_once '../coresection/check_session.php';
?>



<?php include_once("detail-list-function.php"); ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include_once('../module/head.php'); ?>
    <style>
        .weixin-miniapp-code{
            display: none;
        }
    </style>


    <!--分类筛选js-->
    <script type="text/javascript">
        function MM_jumpMenu(targ, selObj, restore) { //v3.0
            eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
            if (restore) selObj.selectedIndex = 0;
        }
    </script>

</head>






<body>

<div id="topbar">
<?php include '../module/topbar.php'; ?>
</div>



<div id="container">
<!--Container端點01-->
<div id="maincontent" class="list">
<!--maincontent端點01-->



<div id="sidebar">
    <?php include '../module/sidebar.php'; ?>
</div>


<div id="content">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend><h1><? echo $sys_title ?></h1></legend>
    </fieldset>





    <div class="select-box layui-form clearfix <? echo $system_part ?>">
        <form action="detail-list.php" >

            <div class="layui-form-item">
                <label class="layui-form-label">关键词</label>
                <div class="layui-input-block">
                    <input type="text"  name="select_keywords" placeholder="名称，型号" autocomplete="off" class="layui-input" value="<? echo $_REQUEST['select_keywords']?>" >
                </div>
            </div>
		
       <?php 
	   $cat_result = mysql_query("select * from ".$table_Prefix."term where belong = 'product' and interm = 'root' and publish = 1 ");


	   ?>
            <div class="layui-form-item search-term">
                <label class="layui-form-label">分类</label>
                <div class="layui-input-block">
                    <select name="cat_id">
                       <option value="0" <?php if($_REQUEST['cat_id'] == 0){ echo 'selected="selected"';}?> >请选择分类</option>
                       <?php 
					   
					   while ($cat = mysql_fetch_array($cat_result)) { //一级
					   ?>
                       <option value="<?php echo $cat['nid']?>" <?php if($_REQUEST['cat_id'] == $cat['nid']){ echo 'selected="selected"';}?>><?php echo $cat['name']?></option>
                       <?php
					   		
					   	$cat2_result = mysql_query("select * from ".$table_Prefix."term where belong = 'product' and interm = 'term1' and publish = 1 and term1 =  ".$cat['nid']);
							
							while ($cat2 = mysql_fetch_array($cat2_result)) { //二级
						?>
								<option value="<?php echo $cat2['nid']?>" <?php if($_REQUEST['cat_id'] == $cat2['nid']){ echo 'selected="selected"';}?>> - <?php echo $cat2['name']?></option>
					    <?php
								$cat3_result = mysql_query("select * from ".$table_Prefix."term where belong = 'product' and interm = 'term2' and publish = 1 and term2 =  ".$cat2['nid']);
                    	    	while ($cat3 = mysql_fetch_array($cat3_result)) { //三级
						?>
                        			<option value="<?php echo $cat3['nid']?>" <?php if($_REQUEST['cat_id'] == $cat3['nid']){ echo 'selected="selected"';}?>> - - <?php echo $cat3['name']?></option>
                        <?php		
								}
							}
					   }
					   ?>

                    </select>
                </div>
            </div>
	   
	   <?php 
	   $brand_result = mysql_query("select * from ".$table_Prefix."term where belong = 'brand' and interm = 'root' and publish = 1 order by name asc ");
	   ?>
            <div class="layui-form-item search-brand">
                <label class="layui-form-label">品牌</label>
                <div class="layui-input-block">
                    <select name="brand_id">
                       <option value="0" <?php if($_REQUEST['brand_id'] == 0){ echo 'selected="selected"';}?>>请选择品牌</option>
                       <?php 
					   
					   while ($brand = mysql_fetch_array($brand_result)) { //一级
					   ?>
                       <option value="<?php echo $brand['nid']?>" <?php if($_REQUEST['brand_id'] == $brand['nid']){ echo 'selected="selected"';}?>><?php echo $brand['name']?></option>
                       <?php
					   		
					   	$brand2_result = mysql_query("select * from ".$table_Prefix."term where belong = 'brand' and interm = 'term1' and publish = 1 and term1 =  ".$brand['nid']);
							
							while ($brand2 = mysql_fetch_array($brand2_result)) { //二级
						?>
								<option value="<?php echo $brand2['nid']?>" <?php if($_REQUEST['brand_id'] == $brand2['nid']){ echo 'selected="selected"';}?>> - <?php echo $brand2['name']?></option>
					    <?php
								$brand3_result = mysql_query("select * from ".$table_Prefix."term where belong = 'brand' and interm = 'term2' and publish = 1 and term2 =  ".$brand2['nid']);
                    	    	while ($brand3 = mysql_fetch_array($brand3_result)) { //三级
						?>
                        			<option value="<?php echo $brand3['nid']?>" <?php if($_REQUEST['brand_id'] == $brand3['nid']){ echo 'selected="selected"';}?>> - - <?php echo $brand3['name']?></option>
                        <?php		
								}
							}
					   }
					   ?>

                    </select>
                </div>
            </div>

			<input type="hidden"  name="now_extender"  value="<?php echo $system_part;?>"/>
            <button class="layui-btn" ><i class="layui-icon">&#xe615;</i> 查找</button>
            
            <button class="layui-btn" type="reset" ><i class="layui-icon">&#x1006;</i> 重置</button>
           
            <br class="clearfloat"/>
        </form>

        <br class="clearfloat"/>
    </div>



 <!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
<div class="list-box clearfix <? echo $system_part ?>">

        <hr/>
        <div class="statistic">
            
            <?php include_once("../module/detail_btn.php");?>
            
			<a class="layui-btn all_qcode" style="display:none;" href="../erweima_all_list.php?nav-itemed=unit&now_extender=<?php echo $system_part?>"><i class="layui-icon">&#xe64a;</i>  二维码批量生成</a>
            
            <div class="function">

                <div class="sort layui-form">
                    <div class="layui-form-item" style="margin-bottom:5px;">
                        <label class="layui-form-label">排序：</label>
                        <div class="layui-input-block">
                            <select lay-filter="MM_jumpMenu" >
    <option <?php if($sortby == ''){echo 'selected="selected"';}?>  value="detail-list.php?nowpageid=<?php echo $nowpageid; ?>&nid=<? echo $trans_nid ?>&sortby=listorder&now_extender=<? echo $system_part ?>">排序选择</option>
    <option <?php if($sortby == 'listorder' && $sortorder == 'desc'){echo 'selected="selected"';}?> value="detail-list.php?nowpageid=<?php echo $nowpageid; ?>&nid=<? echo $trans_nid ?>&sortby=listorder&sortorder=desc&now_extender=<? echo $system_part ?>">人工排序降序</option>
    <option <?php if($sortby == 'listorder' && $sortorder == 'asc'){echo 'selected="selected"';}?> value="detail-list.php?nowpageid=<?php echo $nowpageid; ?>&nid=<? echo $trans_nid ?>&sortby=listorder&sortorder=asc&now_extender=<? echo $system_part ?>">人工排序升序</option>
    <option <?php if($sortby == 'nid' && $sortorder == 'desc'){echo 'selected="selected"';}?> value="detail-list.php?nowpageid=<?php echo $nowpageid; ?>&nid=<? echo $trans_nid ?>&sortby=nid&sortorder=desc&now_extender=<? echo $system_part ?>">输入时间降序</option>
    <option <?php if($sortby == 'nid' && $sortorder == 'asc'){echo 'selected="selected"';}?> value="detail-list.php?nowpageid=<?php echo $nowpageid; ?>&nid=<? echo $trans_nid ?>&sortby=nid&sortorder=asc&now_extender=<? echo $system_part ?>">输入时间升序</option>
    <option <?php if($sortby == 'name' && $sortorder == 'desc'){echo 'selected="selected"';}?> value="detail-list.php?nowpageid=<?php echo $nowpageid; ?>&nid=<? echo $trans_nid ?>&sortby=name&sortorder=desc&now_extender=<? echo $system_part ?>">资料名称升序</option>
    <option <?php if($sortby == 'name' && $sortorder == 'asc'){echo 'selected="selected"';}?> value="detail-list.php?nowpageid=<?php echo $nowpageid; ?>&nid=<? echo $trans_nid ?>&sortby=name&sortorder=asc&now_extender=<? echo $system_part ?>">资料名称降序</option>
</select>
                        </div>
                    </div>
                </div>


            </div>


            <hr/>
        </div>



<div class="list-boxes">



    <table class="layui-table">
        <colgroup>
            <col width="60">
            <col width="100">
            <col>
            <col width="120">
            <col width="300">
        </colgroup>
        <thead>
        <tr>
            <th>编号</th>
            <th>图片</th>
            <th>资料</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        <?php for ($i = 0; $i < $detailnum; $i++) {
        ?>

        <tr>
            <td ><?echo $i+1?></td>

            <td><img src="<? if ($detail_storage[$i]) { echo $detail_storage[$i]; } else { echo $site_domin; } ?>/uploadfiles/<? echo $theme_folder ?>/<?php echo $detail_icon[$i] ?>" /></td>
            <td> <ul class="list-boxing-data">
                    <li class="title-name">
                        <h6 style="font-size: 18px"><label>名称：</label>
                        <a href="detail-edit.php?nid=<?php echo $detail_nid[$i] ?>&now_extender=<? echo $system_part ?>" <? if ($detail_publish[$i] != 1) { echo "class='title-notice'"; } ?>style="font-size:14px; "><?php echo $detail_name[$i] ?></a>
                        </h6>
                    </li>


                    <li class="list-boxing-content">
                        <label>简介：</label>

                        <?
						$now_detail_introduce = cleanhtml($detail_introduce[$i]);
                        if (strlen($now_detail_introduce) > 150) {
                            echo utf8Substr($now_detail_introduce, 0, 50) . "...";
                        } else if (strlen($now_detail_introduce) == 0) {
                            echo "暂无资料";
                        } else {
                            echo $now_detail_introduce;
                        }
                        ?>

                    </li>

                    <br class="clearfloat"/>

 					<li class="brand">
                        <label style="float:left;line-height:28px;">所属品牌：</label>
                        <div style=" float:left; line-height:28px;">
                        <?php

                        $cat_list = gettermdate_brand($detail_nid[$i]) ;

						if($cat_list){

							foreach($cat_list as $val){

								$msg = '根目录' ;

								foreach($val as $val1){
									$msg .= ' \ '.$val1 ;
								}
								$msg .= '<br>' ;
								echo $msg;
							}

						}
						else{
							echo '根目录 \ ' ;
						}
						
                       ?>
                       </div>
                    </li>
                    <br class="clearfloat"/>
                    <li class="term">
                        <label style="float:left;line-height:28px;">所属分类：</label>
                        <div style=" float:left; line-height:28px;">
                        <?php

                        //通过 $detail_nid[$i] 查询出上级分类 （只有一级分类没有使用递归查询）
                        $termResult = mysql_query(" SELECT (SELECT name FROM evo_term WHERE nid =  t.term1 ) AS parentname,t.name AS subname".
                            " FROM evo_detail d".
                            " INNER JOIN evo_relation r ON r.detail_nid = d.nid".
                            " INNER JOIN evo_term  t ON t.nid = r.term_nid".
                            " WHERE r.belong IS NULL AND d.nid = '$detail_nid[$i]' " );

                        $term_list = array();
                        while ($row = mysql_fetch_assoc($termResult)) {
                            $term_list[] = $row;
                        }

//                                                $cat_list = gettermdate($detail_nid[$i]) ;

						if($term_list){

							foreach($term_list as $val){

								$msg = '根目录' ;

								foreach($val as $val1){
									$msg .= ' \ '.$val1 ;
								}
								$msg .= '<br>' ;
								echo $msg;
							}

						}
						else{
							echo '根目录 \ ' ;
						}
						
                       ?>
                       </div>
                    </li>







                </ul>
            </td>


            <td>
                <ul><?php
                if($product_price_show == 1){
                    ?>
                    <li class="price">
                        <label>价格：</label>￥<? echo $detail_price[$i] ?>
                    </li>
                    <?php
                }
                ?>

 
                <li class="publish <? if ($detail_publish[$i] != 1) { echo "title-notice"; } ?>" style="font-size:14px; ">
                    <label>发布状态：</label><?if ($detail_publish[$i] == 1) { echo "是"; } else { echo "否"; }?>
                </li>





                <!--                    <li class="clickrate">-->
                <!--                        <label>点击次数：</label>--><?// echo $detail_clickrate[$i] ?>
                <!--                    </li>-->

                <!--                    <li class="inputtime">-->
                <!--                        <label>输入时间：</label>--><?// echo $detail_inputtime[$i] ?>
                <!--                    </li>-->
                <!--                    <li class="modifytime">-->
                <!--                        <label>修改时间：</label>--><?// echo $detail_modifytime[$i] ?>
                <!--                    </li>-->


                <!--<li class="model">-->
                <!--<label> 型号：</label>--><?// echo $detail_model[$i] ?>
                <!--</li>-->
                <li class="markorder">
                    <label>标记顺序：</label><? echo $detail_markorder[$i] ?>
                </li>
                <li class="listorder">
                    <label>列表顺序：</label><? echo $detail_listorder[$i] ?>
                </li>
                <li class="termorder">
                    <label>分类顺序：</label><? echo $termorder[$i] ?>
                </li>


                <!--<li class="hotsale">-->
                <!--    <label>热销状态：</label>--><?//if ($detail_hotsale[$i] == 1) { echo "是"; } else { echo "否"; }?>
                <!--</li>-->
                <!--            <li class="discount">-->
                <!--                <label>折扣状态：</label>--><?//if ($detail_discount[$i] == 1) { echo "是"; } else { echo "否"; }?>
                <!--            </li>-->
                <li class="recommend">
                    <label>推荐状态：</label><?if ($detail_recommend[$i] == 1) { echo "是"; } else { echo "否"; }?>
                </li>
                <!--            <li class="soldout">-->
                <!--                <label>下架状态：</label>--><?//if ($detail_soldout[$i] == 1) { echo "是"; } else { echo "否"; }?>
                <!--            </li>-->
                <!--            <li class="onsaletime">-->
                <!--                <label>上架时间：</label>--><?// echo $detail_onsaletime[$i] ?>
                <!--            </li>-->
                <li class="mark">
                    <label>标记状态：</label><?if ($detail_mark[$i] == 1) { echo "是"; } else { echo "否"; }?>
                </li>
                </ul></td>

<td>

<div style="margin-bottom:15px;border-bottom: solid 1px #cccccc;padding-bottom: 15px; ">
	
<a href="javascript:void(0)"  class="delete layui-btn  layui-btn-sm" <?php if($detail_is_disabled[$i] == 1){echo 'style= background:#ccc;cursor:not-allowed;';}else{ echo 'onclick="popupBox('. $detail_nid[$i].' )"';}?> > <i class="layui-icon">&#xe640;</i> 删除</a>
<a href="detail-edit.php?nid=<?php echo $detail_nid[$i] ?>&now_extender=<? echo $system_part ?>&nowpageid=<? echo $_REQUEST['nowpageid'] ?>&sortby=<? echo $_REQUEST['sortby'] ?>&term_nid=<? echo $trans_nid ?>" class="modify layui-btn  layui-btn-sm" > <i class="layui-icon">&#xe642;</i> 修改</a>
<a class="weixin-miniapp-code layui-btn  layui-btn-sm" onclick="getWXCode(this)" data-nid="<?php echo $detail_nid[$i] ?>" data-name="<?php echo $detail_name[$i] ?>"> <i class="layui-icon">&#xe677;</i> 小程序码</a>
<a href="/<? echo $detail_url[$i] ?>.html" target="_blank" class="preview layui-btn  layui-btn-sm" > <i class="layui-icon">&#xe621;</i> 预览</a>
<input type="button" class="layui-btn  layui-btn-sm huanqiao-sync-detail" data-nid="<?php echo $detail_nid[$i] ?>" value="同步此产品">
</div>




<a href="../../threeD/detail-show-function.php?nid=<?php echo $detail_nid[$i] ?>" class="threeDbtn layui-btn  layui-btn-sm">3D展示</a>

<a href="../erweima.php?nid=<?php echo $detail_nid[$i] ?>&now_extender=<? echo $system_part ?>" class="threeDbtn layui-btn  layui-btn-sm">二维码设置</a>
</td>



        </tr>
            <?php

        }
        ?>
        </tbody>
    </table>




</div>





</div>




<hr/>

 <?php include_once(ROOT_PATH_ . "/controller/module/page.php"); ?>



<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>
<!--删除box-->
<?php include '../module/deletebar.php'; ?>
<!--删除box end-->

<?php include ROOT_PATH_ . "/controller/module/footer.php"; ?>
<script>
    function getWXCode(e) {
        const nid = e.dataset.nid
        const name = e.dataset.name
        const domain = 'https://dj100.enpingshi.com/'
        $.ajax({
            method: 'GET',
            url: domain + 'api/dangjian100/get_qc_code.php',
            data: {
                path: '/pages/place-audio-brief/place-audio-brief',
                name,
                nid
            },
            contentType: 'application/json',
            success: res => {
                const obj = JSON.parse(res)
                if(obj.code == 0) {
                    window.open(domain + obj.data)
                }
            }
        })
    }

    //  环桥项目多语言term同步
    $('.huanqiao-sync-detail').click(function() {
        const nid = this.dataset.nid
        console.log(this, nid)
        $(this).val('正在同步此产品')
        $('.huanqiao-sync-detail').attr('disabled', 'disabled')
        $('.huanqiao-sync-detail').addClass('layui-btn-disabled')
        syncData(0, nid)
    })

    const lan = ['ara', 'fra', 'jp', 'pl', 'pt', 'ru', 'spa', 'th', 'vie']
    function syncData(index, nid) {
        $.ajax({
            url: `/api/huanqiao/sync_datas.php?from=en&to=${lan[index]}&table=detail&nid=${nid}`,
            success: function() {
                console.log('success: ', lan[index])
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus)
                console.log('erro: ', lan[index])
                console.log(XMLHttpRequest, textStatus, errorThrown)
            },
            complete: function() {
                if(index < lan.length-1) {
                    syncData(index+1, nid)
                }else{
                    // 调用所有语言sync_data后，再循环调用所有语言的 sync_data_detail
                    syncDetailData(0, nid)
                }
            }
        })
    }

    function syncDetailData(index, nid) {
        const btn = $('.huanqiao-sync-detail')
        $.ajax({
            url: `/api/huanqiao/sync_datas_detail.php?from=en&to=${lan[index]}&table=detail&nid=${nid}`,
            success: function() {
                console.log('success: ', lan[index])
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus)
                console.log('erro: ', lan[index])
                console.log(XMLHttpRequest, textStatus, errorThrown)
            },
            complete: function() {
                if(index < lan.length-1) {
                    syncDetailData(index+1, nid)
                }else{
                    btn.removeAttr('disabled')
                    btn.removeClass('layui-btn-disabled')
                    btn.attr('value', '同步此产品')
                }
            }
        })
    }
</script>
</body>
</html>
